<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- author = Wink Hosting (www.winkhosting.com) -->

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta name="generator" content=
  "HTML Tidy for Linux (vers 1 September 2005), see www.w3.org" />
  <meta http-equiv="content-type" content=
  "text/html; charset=us-ascii" />
  <meta name="description" content="description" />
  <meta name="keywords" content="keywords" />
  <meta name="author" content="author" />
  <link rel="shortcut icon" type="image/x-icon" href=
  "http://awk.googlecode.com/svn/branches/tiny/img/favicon.ico" />
  <title>TinyMining : where2.awk</title>
<style type="text/css">
/*<![CDATA[*/
/* 
CSS Document 
Wink Hosting (www.winkhosting.com)
Designed By Alexis Corredor
alexis.corredor@gmail.com
*/
body {
margin-top: 0px;
margin-left: 0px;
margin-right: 0px;
margin-bottom: 0px;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px; 
text-align: left;
align: left;
}
p.left {text-align: left}
/*HEADER*/
#header{
width: 800px;
position:relative; 
height: 162px;
background-image:url(http://awk.googlecode.com/svn/branches/tiny/img/header.jpg);
background-repeat:no-repeat;
}
/*COMPANY NAME IN HEADER*/
#companyname {
position:absolute;
font-family: Verdana, Arial, Helvetica, sans-serif;
color: #FFFFFF;
font-size: 30px;
font-weight: bold;
margin-top:30px;
margin-left:40px;
left: 0px;
top: 0px;
}
#companyname a{
font-family: Verdana, Arial, Helvetica, sans-serif;
color:#FFFFFF;
text-decoration:none;
}
#companyname a:hover{
text-decoration:underline;
}
/*MENU IN HEADER*/
#menu{
position:absolute;
bottom: 20px;
right: 30px;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: bold;
}
#menu a{
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: bold;
color:#333333;
text-decoration:none;
}
#menu a:hover{
text-decoration:underline;
}
/*LEFT PANEL (News, Links, etc.)*/
#leftpanel{
float:left;
width:200px;
}
/*CONTENT*/
#content{
width: 800px;
}
#contenttext{
text-align: left;
float: right;
width: 580px;
}
/*FOOTER*/
.footer{
width: 779px;
height: 32px;
background-image:url(http://awk.googlecode.com/svn/branches/tiny/img/bg_footer.gif);
background-repeat:no-repeat;
clear:both;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: bold;
color:#FFFFFF;
}
/*FOOTER LINKS*/
.footer a{
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: bold;
color:#FFFFFF;
text-decoration:none;
}
.footer a:hover{
text-decoration:underline;
}
/*TABLE*/
.table_top{
width: 204px; 
height: 27px;
background-image:url(http://awk.googlecode.com/svn/branches/tiny/img/table_top.jpg);
background-repeat:no-repeat;
}
.table_content{
width: 204px;
background-image:url(http://awk.googlecode.com/svn/branches/tiny/img/table_content.jpg);
background-repeat:repeat-y;
}
.table_text{
margin-left:15px;
margin-right:15px;
text-align:justify;
}
.table_bottom{
width: 204px; height: 23px;
}
/*TEXT STYLES*/
.news_date {    
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: bold;
color: #0099CC;
}
.body_text {    
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px; align: left;
}
.news_more {    
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FF9900;
font-weight: bold;
}
.news_text {    font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
}
.subtitle_gray {        
font-family:Verdana, Arial, Helvetica, sans-serif;      
font-weight: bold;
font-size: 14px;
color: #CCCCCC;
}
h1 {
margin-top: 0px; padding-top: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 26px; color: #7DA5E0; 
}
.title_blue {
font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 26px; color: #7DA5E0; 
}
.title_panel {  font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
}
pre {
margin-left: 20px;
padding: 1em;
border: 1px dashed #2f6fab;
color: DarkBlue;
background-color: #f9f9f9;
line-height: 1.1em;
}
#title p {
float: right;
text-align: right;
text-width: 750px;
color: white; 
margin: 0 20px 0px 0; 
line-height: 1.2em;
padding-top: 5px;
padding-bottom: 5px;
padding-top: 20px;
}
p.tags {
font-size: x-small;
margin-top: 0px;
margin-botton: 0px;
text-align: right;
color: #AAA;
}
h1 h2 h3 h4 h5 h6 h7 { color:  #7DA5E0; }
h2 { border-top: 1px solid #7DA5E0; } 
/*]]>*/
</style>
</head>

<body>
  <div id="page" align="center">
    <div id="header">
     <div id="title">google-search  </div> 
      <div id="companyname" align="left">
        where2.awk
      </div>

      <div align="right" class="links_menu" id="menu">
	    mennu
      </div>
    </div><br />

    <div id="content">
      <div id="leftpanel">

        <div class="table_top">
          <div align="center">
            <span class="title_panel">News</span>
          </div>
        </div>

        <div class="table_content">
          <div class="table_text">

             news
          </div>
        </div>
    
        <div class="table_bottom">
          <img src="http://awk.googlecode.com/svn/branches/tiny/img/table_bottom.jpg"
          width="204" height="23" border="0" alt="" />
        </div>
        <p/>

        <div class="table_top">
          <div align="center">
            <span class="title_panel">News</span>
          </div>
        </div>

        <div class="table_content">
          <div class="table_text">
				Links
          </div>
        </div>
    
        <div class="table_bottom">
          <img src="http://awk.googlecode.com/svn/branches/tiny/img/table_bottom.jpg"
          width="204" height="23" border="0" alt="" />
        </div>
        <p/>
        <div class="table_top">
          <span class="title_panel">Links</span>
        </div>

        <div class="table_content">
          <div class="table_text">
			SEE also
          </div>
        </div>

        <div class="table_bottom">
          <img src="http://awk.googlecode.com/svn/branches/tiny/img/table_bottom.jpg"
          width="204" height="23" border="0" alt="" />
        </div>
        <p/>

      </div>

      <div id="contenttext">
         <img src="http://awk.googlecode.com/svn/branches/tiny/img/babel.jpg" align=right width=200  
		        style="margin: 3px; padding: 1px; border: 1px solid #CCC;">


<h1> @include "lib.awk"</h1>

<ul>
<li> <a href="#1">Globals</a>
<ul>
<ul>
<ul>
<li> <a href="#2"> A </a>
<li> <a href="#3"> K == </a>
<li> <a href="#4"> R </a>
</ul></ul></ul></ul>

<a name="1"></a><h2>Globals</h2>
<p>
Cluster id
</p>
<a name="2"></a><h5> A </h5>
<p>
Number of attribtes
</p>
<a name="3"></a><h5> K == </h5>
<p>
Class attribute id
</p>
<a name="4"></a><h5> R </h5>
<p>
Number of rows.
 
Parser
======
</p>
<pre>
 BEGIN        { TooSmall=20; Pinch = 10^-6; 	CONVFMT = "%.10f"; Missing="?"}
  /@attribute/ { Name[++A]=$2; 
                if ($3 ~ /(numeric|integer|real|float)/) { Num[A] } else { Sym[A] }
              }
 /@data/      { FS=","; C=0
                K = K&lt;0 ? K = A + 1  + K : K; 
                next }
 /@/          { next }
              { gsub(/%.*/,""); gsub(/[ \t]*/,""); if (/^$/) next }
 NF==A        { cells(C,initRow()) }
 END          { divide(0) }
 
#### storage


 BEGIN{_R=0}
 function initRow(    col) {
 	_R++
     for(col=1;col&lt;=A;col++) Data[_R, col] = $col
 	return _R
 } # end _R
 function cells(c,row,      col,val) {
 	Has[c][row] 
 	for(col in Num) 
 		if ((val=Data[row,col]) != Missing) 
 			numCell(c,row,col,val)
 	for(col in Sym) 
 		if ((val=Data[row,col]) != Missing) 
 			symCell(c,row,col,val)
 }
 function numCell(c,row,col,val) {
 	N[c,col]++
 	Sum[c,col] += val
 	SumSq[c,col] += val * val
 	Value[c,col][row]=val	
 }
 function symCell(c,row,col,val) {
 	Value[c,col][val]++
 	Values[c,col]++
 }
#### splitter
 function split_on(c,   col,tmp,max,out) {
 	for(col in Num) if (col != K) tmp[col] = sd( SumSq[c,col],Sum[c,col],N[c,col]) 
 	for(col in Sym) if (col != K) tmp[col] = ent(Value[c,col],Values[c,col]) 
 	for(col in Num) if (col != K) tmp[col] = norm_sd(  tmp[col])
 	for(col in Sym) if (col != K) tmp[col] = norm_ent( tmp[col])
 	for(col in tmp) if (tmp[col] > max) { max= tmp[col]; out=col}
 	return out
 }
 function divide(c,  left,right,div,  kids,kid,action) {
 	if  (length(Has[c]) &lt;= TooSmall) return Dead[c]=1
 	Split[c] = div = split_on(c)
 	if (div in Num)
           divideNum(c,Split[c],kids, Has[c], Value[c,div])
     else  divideSym(c,Split[c],kids, Has[c], Value[c,div])
 	for(kid in kids)
 		divide(kids[kid])
 }
 function divideNum(c,div,kids,rows,values,   all,n,median,row) {
 	n = asort(values,all)	
 	Splitter[c] = median = all[int(n/2)]
 	kids[1] = newC(c,0)
 	kids[2] = newC(c,median)
 	for(row in rows) 
 		Data[row,div] &lt;= median ? cells(kids[1],row) : cells(kids[2],row)
 }	
 function divideSym(c,div,kids,rows,values,    val,row) {
 	for(val in values) kids[val] = newC(c,val)
 	for(row in rows)   cells(kids[Data[row,div]],row)	
 }
 function newC(c,val) {
 	C++
 	Parent[C] = c 
 	Child[c][val] = C
 	return C
 }
#### tree print
 function cprint(c,pre,pad,             op, vals,val) {
 	if (! (c in Split)) return 0
 	print pad c ":" Name[Split[c]] " (" length(Has[c]) ")"
 	op = Split[c] in Num ? ">=" : "="
 	if(length(Child[c]))
 		for(val in Child[c]) 
 			cprint(Child[c][val],op val, pad "  ")
 }
 #### diversity measures
 BEGIN {_Minsd= 10^31; _MaxSd = -1*_MinSd
        _MinE= 10^31;   _MaxE = -1*_MinE}
 
 function norm_ent(s) { return norm(s,_MinE ,_MaxE)  }
 function norm_sd(s){ return norm(s,_MinSd,_MaxSd) }
 
 function sd(sumSq,sumX,n,tmp) {
     tmp = sqrt((sumSq-((sumX*sumX)/n))/(n-1));
 	if (tmp &lt; _Minsd) _Minsd = tmp
 	if (tmp > _Maxsd) _Maxsd = tmp
 	return tmp
 }
 function ent(a,n,      i,p,tmp) {
 	for(i in a)  
 		if (a[i] > TooSmall) {
 			p = a[i]/n 
 		    tmp += -1*p*log(p)/log(2)
 	}
 	if (tmp &lt; _MinE) _MinE = tmp
 	if (tmp > _MaxE) _MaxE = tmp
 	return tmp
 } # end _Minsd  _Maxsd _MinE MaxE

        <p>&nbsp;</p>
      </div><br />
      <br />

      <div class="footer">
			footer
      </div>
    </div>
  </div>
</body>
</html>


